﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.AspNetCore.Mvc.Authorization;
using Abp.AutoMapper;
using KelonProud.Administration.Dtos;
using KelonProud.Administration.Managers.Application;
using KelonProud.Administration.Managers.Authorization;
using KelonProud.Administration.Managers.MultiTenancy;
using KelonProud.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace KelonProud.Administration.Controllers
{
    [AbpMvcAuthorize]
    [Route("admin/[controller]/[action]")]
    public class RoleController : KelonProudControllerBase
    {
        private readonly TenantManager _tenantManager;
        private readonly RoleManager _roleManager;
        private readonly UserManager _userManager;
        private readonly NavigationManager _navigationManager;

        public RoleController(TenantManager tenantManager,
            RoleManager roleManager, UserManager userManager, NavigationManager navigationManager)
        {
            _tenantManager = tenantManager;
            _roleManager = roleManager;
            _userManager = userManager;
            _navigationManager = navigationManager;
        }

        public ActionResult Index()
        {
            return View("KelonProud.Administration.Views.Role.Index");
        }

        public ActionResult Create()
        {
            var model = new RoleInputDto()
            {
                TenantId = AbpSession.TenantId
            };

            return View("KelonProud.Administration.Views.Role.Edit", model);
        }

        public async Task<ActionResult> Edit(int id)
        {
            var role = await _roleManager.GetRoleByIdAsync(id);

            if (role == null)
                throw new Exception("需要编辑的用户角色不存在!");

            var model = role.MapTo<RoleInputDto>();


            return View("KelonProud.Administration.Views.Role.Edit", model);
        }
    }
}
